home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / tegl6b.zip / INTROPAK.EXE / lha / VIRTMEM.DOC < prev   
Text File  |  1991-08-16  |  8KB  |  241 lines

  1. {-----------------------------------------------------------------------------}
  2. {               TEGL Windows ToolKit II                  }
  3. {          Copyright (C) 1990, TEGL Systems Corporation              }
  4. {                All Rights Reserved.                  }
  5. {-----------------------------------------------------------------------------}
  6.  
  7. {$I switches.inc}
  8. {$I-}
  9.  
  10. Unit VirtMem;
  11.  
  12. INTERFACE
  13.  
  14. USES Dos,            {reading and writing dos files}
  15.      Crt,            {sound when accessing virtual}
  16.      errorlog;
  17.  
  18. TYPE
  19.      SegOfs = RECORD
  20.          Ofst, Segm : Word;
  21.           END;
  22.  
  23.      FreeListRecPtr = ^FreeListRec;
  24.      FreeListRec    =  RECORD
  25.               OrgPtr : Pointer;     {pointer to the start of the block}
  26.               EndPtr : Pointer;     {pointer to the end of the block}
  27.                END;
  28. {$IFNDEF NoVirt}
  29.      EMSBlockPtr = ^EMSBlock;
  30.      EMSBlock     = RECORD
  31.               nextblockptr  : EMSblockPtr;
  32.               Handle        : Word;       {Multiple handles}
  33.               EMSPage        : Word;       {Pages allocated}
  34.            END;
  35.  
  36.      EMSFile     = ^EMSFileRec;
  37.      EMSFileRec  = RECORD
  38.               PageOffset    : Word;    {current offset within page}
  39.               BaseAddress   : Word;
  40.               EMSPosition   : longint;
  41.               TotalPages    : Word;    {Total number of 16k pages}
  42.               RootBlkPtr    : EMSBlockPtr;
  43.            END;
  44. {$ENDIF}
  45.  
  46.      errorproc         = Function(procnum : longint):Word;
  47.  
  48. {$IFNDEF NoVirt}
  49.      Signate         = String[4];
  50.  
  51.      VDskFreePtr     = ^VDskFreeRecord;
  52.      VDskFreeRecord     = RECORD
  53.                   NextVDskFree : VDskFreePtr;
  54.                   StartBlock   : longint;
  55.                   EndBlock       : longint;
  56.                   Signature    : Signate;
  57.                   BlockFree    : Boolean;
  58.                END;
  59.  
  60.      VDskBlockSizeRecord = RECORD
  61.                   BSize       : longint;
  62.                   RealSize       : longint;
  63.                   Signature    : signate;
  64.                   BlockFree    : Boolean;
  65.                   Chksum       : Word;
  66.                END;
  67.  
  68.      VDskFile         = ^VDskFileRecord;
  69.      VDskFileRecord     = RECORD
  70.                   VDskFreePtrChain : VDskFreePtr;
  71.                   VDskTopOfFile    : longint;
  72.                   VDskAttribute    : Word;
  73.                 { VDskPacketSave   : longint;}
  74.                   CASE EMSType : Boolean of
  75.                  FALSE : (VDskHeapFile: File);
  76.                  TRUE  : (VEMSHeapFile: EMSFile);
  77.                END;
  78.  
  79.  
  80.      VirtualPtr      = ^VirtualRec;
  81.      VirtualRec      = RECORD
  82.                   nxtptr         : VirtualPtr;
  83.                   lstptr         : VirtualPtr;
  84.                   MemorySize     : longint;
  85.                   MemoryPtr      : Pointer;
  86.                   MemoryLock     : Boolean;
  87.                   MemoryInUse    : Boolean;
  88.                   MemoryPageOut  : Boolean;
  89.                   MemoryPagePtr  : longint;
  90.                   VPReferBack    : Pointer;
  91.                   VPLastMemPtr   : Pointer;
  92.                   MemoryLevel    : byte;
  93.                END;
  94.  
  95.  
  96.  
  97. CONST
  98. {$IFDEF VSOUND}
  99.    VirtualSound   : Boolean    = TRUE;
  100. {$ENDIF}
  101.    VirtualEMSHeap : VDskFile   = NIL;
  102.    VirtualDSKHeap : VDskFile   = NIL;
  103.    TriedEMS      : Boolean    = FALSE;
  104.    VirtualAnchor  : Virtualptr = NIL;
  105.  
  106.    MaxPageEMSOpen : Word = 25;    {400k of EMS memory}
  107.    MinPageEMSAlloc: Word = 16;    {256k of subsequent EMS memory}
  108.  
  109.    VDskReadWrite = 1;
  110.    VDskTemporary = 2;
  111.    VDskStatus     : Word = 0;
  112.  
  113.    MemoryLevel     : byte = 0;
  114.  
  115. {$ENDIF}  {-- Novirt }
  116.  
  117. CONST
  118.    HugeMin        : longint = 10000;
  119.    StandardHeapSize : longint = 10000;
  120.    CGetMemThreshold : longint = 0;
  121.    UpperHeapSize    : longint = 0;
  122.  
  123.    THeapOrg        : Pointer = nil;
  124.    THeapPtr        : Pointer = nil;
  125.    TFreePtr        : Pointer = nil;
  126.    THeapTop        : Pointer = nil;
  127.    TFreeMin        : word    = 2000;
  128.    HeapMemInit        : boolean = false;
  129.    HeapChkByte        : byte = $72;
  130.    ReservedByte     : Pointer = nil;
  131.  
  132.    MonitorRMax        : longint = 1024;
  133.    MonitorRMem        : longint = 5120;
  134.    MonitorRInc        : longint = 16384;
  135.    HeapErrorFlag    : boolean = false;
  136.    invirtual        : boolean = false;
  137.  
  138. { Virtual Error passes a word indicating where Virtual had error.
  139.        1 -  MoveFromVirtual
  140.        2 -  MoveToVirtual
  141.        3 -  FreeVirtual
  142.        4 -  CloseVirtual
  143. }
  144. { VDskError passes a word indicating where Virtual Disk had error.
  145.        1 -  VDskGetMem
  146.        2 -  VDskFreeMem
  147.        3 -  VDskReadHeapData
  148.        4 -  VDskWriteHeapData
  149.        5 -  VDskCloseHeapFile
  150.        6 -  VDskOpenHeapFile
  151. }
  152. VAR VDskError     : ErrorProc;
  153.     VirtualError : ErrorProc;
  154.     HugeHeapError: ErrorProc;
  155.     VirtMemError : ErrorProc;
  156.     EMS_Status     : Word;
  157.     VirtMem_ExitSave : Pointer;
  158.  
  159. {-- dummy error return procedure }
  160.  
  161. Function ReturnDiskError(code:longint) : Word;
  162.  
  163. {$IFNDEF NoVirt}
  164. Procedure SetMaxEMSSize;
  165. Procedure UseHardDisk(yesno:Boolean);
  166. Procedure MoveFromVirtual(DataPtr:Pointer; VirtualHeapPtr:longint);
  167. Function  MoveToVirtual(DataPtr:Pointer; HeapSize:longint) : longint;
  168. Procedure FreeVirtual(VirtualHeapPtr:longint);
  169. Procedure CloseVirtual;
  170. Function VirtualMemUsed : longint;
  171.  
  172. {------EMS------}
  173. Function EmmInstalled: Boolean;
  174. Function EMSPagesAvailable (VAR TotalEMSPages,Pages_Available: Word): Word;
  175. Function AllocateExpandedMemoryPages(PagesNeeded:Word; VAR Handle:Word): Word;
  176. Function MapExpandedMemoryPages(Handle,LogicalPage,PhysicalPage: Word): Word;
  177. Function GetPageFrameBaseAddress(VAR PageFrameAddress: Word):Word;
  178. Function DeallocateExpandedMemoryPages (Handle: Word): Word;
  179. Function GetVersionNumber(VAR VersionString: String): Word;
  180. Function GetHandleCountUsed (VAR NumberOfHandles: Word): Word;
  181. Function GetPagesOwnedByHandle (Handle: Word; VAR PagesOwned:Word): Word;
  182.  
  183. {------Virtual Disk------}
  184. Function  VDSKGetMem(VDskPacket:VDskFile; HeapSize:longint; signature:Signate) : longint;
  185. Procedure VDSKFreeMem(VDskPacket:VDskFile; VDskHeapPtr:longint);
  186. Procedure VDSKWriteHeapData(VDskPacket:VDskFile; DataPtr:Pointer; VDskHeapPtr:longint);
  187. Procedure VDSKReadHeapData(VDskPacket:VDskFile; DataPtr:Pointer; VDskHeapPtr:longint);
  188. Procedure VDskCloseHeapFile(VDskPacket:VDskFile);
  189. Function  VDskOpenHeapFile(VDskFileName : String; VDskAttribute:Word) : VDskFile;
  190. Function  VEMSOpenHeapFile : VDskFile;
  191. Procedure VDskShowFreeList(VDskPacket:VDskFile);
  192.  
  193. {------Ems Drive------}
  194. Function  EMSOpen(MinimumPages:Word) : EMSFile;
  195. Procedure EMSSeek(EMSRamFile:EMSFile; Position:longint);
  196. Procedure EMSBlockWrite(EMSRamFile:EMSFile; buffer:Pointer; bytestowrite:longint);
  197. Procedure EMSBlockRead(EMSRamFile:EMSFile; buffer:Pointer; bytestoread:longint);
  198. Procedure EMSClose(EMSRamFile:EMSFile);
  199.  
  200. {$ENDIF}  {-- NoVirt }
  201.  
  202. {------Memory --------}
  203. Procedure InitTEGLHeap;
  204. Function  ReservedMemAvail : longint;
  205. Function  ReservedMaxAvail : longint;
  206. Function  CMaxAvail : longint;
  207. Function  CMemAvail : longint;
  208. Procedure CGetMem(VAR Pt; Heapsize : LongInt);
  209. Procedure FGetMem(VAR Pt; HeapSize : LongInt);
  210. Procedure CFreeMem(VAR Pt; Heapsize : LongInt);
  211. Procedure MoveBytes(Buffer1,Buffer2:Pointer; BytestoMove:Word);
  212. Procedure ReserveHugeMinimum(MinimumSize : longint);
  213. Procedure SetStandardHeapSize(Heapsize : LongInt);
  214.  
  215. {------Virtual Memory------}
  216. Procedure VPUnLock(vp:virtualptr);
  217. procedure VPlock(vp:virtualptr);
  218.  
  219. Function  VMPageOut(memrequest:longint) : Boolean;
  220. procedure VPUse(vp:virtualptr);
  221. procedure VPAccess(vp:virtualptr; Var rfptr);
  222. Procedure VPGetMem(VAR VP:virtualptr; HeapSize : LongInt);
  223. Procedure VPFreeMem(vp:virtualptr);
  224. Procedure VPPageOut(VP : virtualptr);
  225. Procedure VPPageIn(vp:virtualptr);
  226. procedure VPUnUse(vp:virtualptr);
  227. procedure VMSetLevel(level:byte);
  228. function  VMGetLevel : byte;
  229. procedure PushVPlevel;
  230. procedure PopVPlevel;
  231. procedure MonitorCheck(rmax,rmem,moremem : longint);
  232. procedure SetMonitorThresholds(rmax,rmem,moremem : longint);
  233.  
  234. Function Linear(P : Pointer) : LongInt;
  235. Function LinearToPointer(L : LongInt) : Pointer;
  236. Function PtrDiff(P1, P2 : Pointer) : LongInt;
  237.  
  238. Function MemoryShuffle(size:longint): Word;
  239.  
  240. IMPLEMENTATION
  241.